<template>
  <div class="app-container">
    <div class="filter-container">
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" v-if="formThead.id" placeholder="id" v-model="listQuery.id"></el-input>
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" v-if="formThead.title" placeholder="标题" v-model="listQuery.title"></el-input>
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" v-if="formThead.content" placeholder="内容" v-model="listQuery.content"></el-input>
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" v-if="formThead.create_time" placeholder="创建时间" v-model="listQuery.create_time"></el-input>
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" v-if="formThead.over_time" placeholder="过期时间" v-model="listQuery.over_time"></el-input>
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" v-if="formThead.status" placeholder="状态" v-model="listQuery.status"></el-input>
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" v-if="formThead.time" placeholder="活动时间" v-model="listQuery.time"></el-input>
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" v-if="formThead.address" placeholder="活动地点" v-model="listQuery.address"></el-input>
            <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <addPage @getLists="getLists"></addPage>
    </div>

    <div class="filter-container">
            <el-checkbox  v-model="formThead.id" label="id">id</el-checkbox>
            <el-checkbox  v-model="formThead.title" label="标题">标题</el-checkbox>
            <el-checkbox  v-model="formThead.content" label="内容">内容</el-checkbox>
            <el-checkbox  v-model="formThead.create_time" label="创建时间">创建时间</el-checkbox>
            <el-checkbox  v-model="formThead.over_time" label="过期时间">过期时间</el-checkbox>
            <el-checkbox  v-model="formThead.status" label="状态">状态</el-checkbox>
            <el-checkbox  v-model="formThead.time" label="活动时间">活动时间</el-checkbox>
            <el-checkbox  v-model="formThead.address" label="活动地点">活动地点</el-checkbox>
          </div>

    <el-table :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row style="width: 100%;">
            <el-table-column align="center" v-if="formThead.id" label="id">
        <template slot-scope="scope">
          <span>{{scope.row.id}}</span>
        </template>
      </el-table-column>
            <el-table-column align="center" v-if="formThead.title" label="标题">
        <template slot-scope="scope">
          <span>{{scope.row.title}}</span>
        </template>
      </el-table-column>
            <el-table-column align="center" v-if="formThead.content" label="内容">
        <template slot-scope="scope">
          <span>{{scope.row.content}}</span>
        </template>
      </el-table-column>
            <el-table-column align="center" v-if="formThead.create_time" label="创建时间">
        <template slot-scope="scope">
          <span>{{scope.row.create_time}}</span>
        </template>
      </el-table-column>
            <el-table-column align="center" v-if="formThead.over_time" label="过期时间">
        <template slot-scope="scope">
          <span>{{scope.row.over_time}}</span>
        </template>
      </el-table-column>
            <el-table-column align="center" v-if="formThead.status" label="状态">
        <template slot-scope="scope">
          <span>{{scope.row.status}}</span>
        </template>
      </el-table-column>
            <el-table-column align="center" v-if="formThead.time" label="活动时间">
        <template slot-scope="scope">
          <span>{{scope.row.time}}</span>
        </template>
      </el-table-column>
            <el-table-column align="center" v-if="formThead.address" label="活动地点">
        <template slot-scope="scope">
          <span>{{scope.row.address}}</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <editPage v-bind:row_data="scope.row" @getLists="getLists"></editPage>
          <el-button  @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import { getList, del } from '@/api/activity/activity'
  import store from '@/store'
  import waves from '@/directive/waves' // 水波纹指令
  import addPage from './addPage'
  import editPage from './editPage'
  export default {
    name: 'complexTable',
    directives: {
      waves
    },
    components: { addPage, editPage },
    data() {
      return {
        tableKey: 0,
        list: null,
        total: null,
        listLoading: true,
        listQuery: {
                  id: undefined,
                  title: undefined,
                  content: undefined,
                  create_time: undefined,
                  over_time: undefined,
                  status: undefined,
                  time: undefined,
                  address: undefined,
                 page: 1,
         limit: 20
        },
        formThead: {
                id: true,
                          title: true,
                          content: true,
                          create_time: true,
                          over_time: true,
                          status: true,
                          time: true,
                          address: true,
                          }
      }
    },
    created() {
      this.getLists()
    },
    methods: {
      getLists() {
        this.listLoading = true
        getList(store.getters.token, this.listQuery).then(response => {
          this.list = response.data.list.data
          this.total = response.data.list.total
          this.listLoading = false
        })
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getLists()
      },
      handleSizeChange(val) {
        this.listQuery.limit = val
        this.getLists()
      },
      handleCurrentChange(val) {
        this.listQuery.page = val
        this.getLists()
      },
      del(id) {
        this.$message.info('正在删除' + id)
        del(store.getters.token, { id: id }).then(res => {
          this.$message.info('已经删除' + id)
          this.getLists()
        })
      }
    }
  }
</script>
